﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using EQT.Bll;
using EQT.Model;
using EQT.Dal;
using System.Collections.Generic;

/// <summary>
/// UploadNamePlate 的摘要说明, 为设备照片铭牌上传附件
/// </summary>
public class UploadNamePlate : IUploadFile
{
    private DaEquip daEquip = new DaEquip(DaCommon.DefaultDb);
    private DaTfile datfile = new DaTfile(DaCommon.DefaultDb);
    public UploadNamePlate()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }

    #region IUploadFile 成员

    public void InitUpload(IUploadPage up, System.Collections.Specialized.NameValueCollection nvc)
    {
        //给设备ID，给定返回URL

        up.SetConfigValue("UPLOAD_MODE","nameplate");
        string deviceid = nvc["deviceid"];//获取设备ID号

        if (String.IsNullOrEmpty(deviceid) || deviceid.Trim().Length == 0)
        {
            Utility.SiteError("缺失所必需的参数【设备编号或模板类型】", up.Response);
            return;
        }
        else
        {
            up.SetConfigValue("DEVICEID", deviceid);
        }

        MoEquip moe = daEquip.GetEntity(deviceid);

        up.SetPageTitle(String.Format("为设备【{0}】上传铭牌图片：", moe.Equip_Id + ":" + moe.Equip_Name));
    }

    public int Upload1(IUploadPage up, MoTfile file, string opter_id)
    {
        MoRefFile modref = new MoRefFile();
        modref.Eid = up.GetConfigValue("DEVICEID").ToString();
        modref.File_Id = file.File_Id;
        modref.Rf_Id = SequenceKeys.GenerateReferFileID();
        try
        {
            return datfile.AddFileEx(file, modref);
        }
        catch (DalException de)
        {
            Utility.GlobalLog.Error("添加单个文件失败!", de);
            Utility.SiteError("添加单个文件失败!", up.Response);
            return -1;
        }
        
    }

    public int UploadedMuliti(IUploadPage up, List<MoTfile> files, string opter_id)
    {
        throw new Exception("The method or operation is not implemented.");
    }

    public string GetReturnUrl(IUploadPage up)
    {
        return String.Format("Equipment.aspx?deviceid={0}&mode={1}", up.GetConfigValue("DEVICEID"), "edit"); 
    }

    #endregion
}
